package com.t7;

/**
 * Created by xuyiwei on 2018/7/18.
 */
class Component1 {
    public Component1() {
        System.out.println("Component1");
    }

    public void dispose(){
        System.out.println("Component1被销毁");
    }
}

class Component2 {
    public Component2() {
        System.out.println("Component2");
    }

    public void dispose(){
        System.out.println("Component2被销毁");
    }
}

class Component3 {
    public Component3() {
        System.out.println("Component3");
    }

    public void dispose(){
        System.out.println("Component3被销毁");
    }
}

class Root {
    Component1 c1 = new Component1();
    Component2 c2 = new Component2();
    Component3 c3 = new Component3();

    public Root() {
        System.out.println("Root");
    }

    public void dispose(){
        c1.dispose();
        c2.dispose();
        c3.dispose();
        System.out.println("Root被销毁");
    }
}

class Stem extends Root {
    Component1 c1 = new Component1();
    Component2 c2 = new Component2();
    Component3 c3 = new Component3();

    public Stem() {
        System.out.println("Stem");
    }

    public void dispose(){
        c1.dispose();
        c2.dispose();
        c3.dispose();
        System.out.println("Stem被销毁");
        super.dispose();
    }
}

public class E09_ConstructorOrder2 {
    public static void main(String args[]) {
        new Stem();
    }
}